package com.kc.sys.config;
import com.kc.sys.domain.User;
import com.kc.sys.util.WebUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author forever_love
 * @create 2019--11--12 14:25
 **/
public class LoginIntercepetor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        User user = (User)WebUtils.getSession().getAttribute("user");
        if(null!=user){
            return true;
        }else{
            try {
                request.getRequestDispatcher("/sys/loginFront").forward(request,response);
            } catch (ServletException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return true;
        }
    }
}
